home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / islive.zip / ISALIVE.TXT < prev   
Text File  |  1993-03-01  |  2KB  |  63 lines

  1. isalive.exe
  2.  
  3. I needed to use ping in a batch file to determine if a particular host was 
  4. 'up'.  Unfortunately, the ping supplied with Novell's LAN Workplace didn't  
  5. set a DOS errorlevel to use in a conditional in a batch file.  I didn't find a 
  6. suitable (free) utility, so I wrote one.
  7.  
  8. Basically, it's a filter used on the output of ping that sets the DOS 
  9. errorlevel to 0 (normal) if the pinged device is alive, or to 1 is the device 
  10. is not alive.  It simply looks for the string 'alive' in the output of ping.
  11.  
  12.  
  13. The relevent section of an autoexec.bat file:
  14.  
  15. ping hostname | isalive
  16. if errorlevel 1 goto DEAD
  17. rem hostname is alive, put needed lines between here and goto END
  18.  
  19. goto END
  20. :DEAD
  21. rem hostname is not responding, put needed lines between here and END
  22.  
  23. :END
  24.  
  25.  
  26.  
  27. The source code for 'isalive.c'
  28.  
  29. /* isalive.c    use with 'ping' to set DOS errorlevel to 1 if not alive
  30.                                               0 if alive
  31.     Mark Gogins 2/28/93 Compuserve 70243,1412
  32.     Please feel free to modify any and all of this as you wish, even sell
  33.     it for big bucks if you can. This program is free, clear, and released  
  34.     to the public domain.  The author assumes no responsibility for any 
  35.     damage or loss caused by the use of this program, however it
  36.     comes down.
  37. */
  38.  
  39. #include <stdio.h>
  40. #include <string.h>
  41. #include <process.h>
  42. #include <stdlib.h>
  43.  
  44. #define DEAD 1
  45. #define ALIVE 0
  46.  
  47. void main()
  48. {
  49.     char temp[128];
  50.     gets(temp);
  51.     if ( strstr(temp,"alive"))
  52.                 {
  53.                     printf(temp);
  54.                     _exit(ALIVE);
  55.                  }
  56.                  else
  57.                  {
  58.                          printf(temp);
  59.                        _exit(DEAD);
  60.                  }
  61. }
  62.  
  63.